const fs = require('fs-extra');
const path = require('path');

/**
 * 查找目录中的所有 EPUB 文件
 * @param {string} directory - 要搜索的目录路径
 * @returns {Promise<string[]>} EPUB 文件路径数组
 */
async function findEpubFiles(directory) {
  const files = [];
  
  async function scanDir(dir) {
    const items = await fs.readdir(dir);
    
    for (const item of items) {
      const fullPath = path.join(dir, item);
      const stats = await fs.stat(fullPath);
      
      if (stats.isDirectory()) {
        await scanDir(fullPath);
      } else if (stats.isFile() && item.toLowerCase().endsWith('.epub')) {
        files.push(fullPath);
      }
    }
  }
  
  await scanDir(directory);
  return files;
}

module.exports = {
  findEpubFiles
}; 